package at.ac.univie.zsu.aguataplan.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import javax.validation.constraints.Size;

/**
 * @author gerry
 * 
 */
@Entity
public class Video {

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column
	private Long id;

	@Version
	@Column
	private Integer version;

	@Column(nullable = false, unique = true)
	@Size(min = 1)
	// @Length(min = 1)
	private String name;

	@Column
	private String description;

	@Column(nullable = false, unique = true)
	@Size(min = 1)
	private String locationPath;

	@Column(nullable = false)
	private Double length;

	@Column
	private String videoCodec;

	@Column
	private String audioCodec;

	@ManyToOne(fetch = FetchType.EAGER)
	private Tournament refTournament;

	@OneToMany(cascade = CascadeType.ALL)
	private Set<DetectedEvent> refDetectedEvent = new HashSet<DetectedEvent>();

	@OneToMany(cascade = CascadeType.ALL)
	private Set<BallPosession> refBallPosession = new HashSet<BallPosession>();

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public Video() {

	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public String toString() {
		return this.name;
	}

	public String toStringExtended() {
		StringBuilder sb = new StringBuilder();
		sb.append("AudioCodec: ").append(getAudioCodec()).append(", ");
		sb.append("Description: ").append(getDescription()).append(", ");
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("Length: ").append(getLength()).append(", ");
		sb.append("LocationPath: ").append(getLocationPath()).append(", ");
		sb.append("RefBallPosession: ").append(getRefBallPosession() == null ? "null" : getRefBallPosession().size())
				.append(", ");
		sb.append("RefDetectedEvent: ").append(getRefDetectedEvent() == null ? "null" : getRefDetectedEvent().size())
				.append(", ");
		sb.append("RefTournament: ").append(getRefTournament()).append(", ");
		sb.append("Version: ").append(getVersion()).append(", ");
		sb.append("VideoCodec: ").append(getVideoCodec());
		return sb.toString();
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getLocationPath() {
		return locationPath;
	}

	public void setLocationPath(String locationPath) {
		locationPath = locationPath.replace("/", "\\");

		this.locationPath = locationPath;
	}

	public Double getLength() {
		return length;
	}

	public void setLength(Double length) {
		this.length = length;
	}

	public String getVideoCodec() {
		return videoCodec;
	}

	public void setVideoCodec(String videoCodec) {
		this.videoCodec = videoCodec;
	}

	public String getAudioCodec() {
		return audioCodec;
	}

	public void setAudioCodec(String audioCodec) {
		this.audioCodec = audioCodec;
	}

	public Tournament getRefTournament() {
		return refTournament;
	}

	public void setRefTournament(Tournament refTournament) {
		this.refTournament = refTournament;
	}

	public Set<DetectedEvent> getRefDetectedEvent() {
		return refDetectedEvent;
	}

	public void setRefDetectedEvent(Set<DetectedEvent> refDetectedEvent) {
		this.refDetectedEvent = refDetectedEvent;
	}

	public Set<BallPosession> getRefBallPosession() {
		return refBallPosession;
	}

	public void setRefBallPosession(Set<BallPosession> refBallPosession) {
		this.refBallPosession = refBallPosession;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
